package com.example.chapp.control;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;

import androidx.annotation.Nullable;

import com.example.chapp.MainActivity;
import com.example.chapp.R;
import com.example.chapp.entity.*;
import com.example.chapp.listutil.*;
import com.example.chapp.util.HttpCallback;
import com.example.chapp.util.httputil;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;

import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;

public class fenleiactive extends Activity {

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.fenlei);

        request();


        View but1=findViewById(R.id.sy);
        but1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent=new Intent(fenleiactive.this, shouyeactive.class);
                startActivity(intent);
            }
        });
        View but2=findViewById(R.id.wd);
        but2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent=new Intent(fenleiactive.this, wodeactive.class);
                startActivity(intent);
            }
        });

    }
    public void request(){

        httputil.sendRequest("http://192.168.223.1:8080/getc", "GET", null, new HttpCallback() {
            @Override
            public void onSuccess(InputStream in) {
                String s = httputil.decodeAsString(in);
                Gson gson=new Gson();
                result r=gson.fromJson(s,new TypeToken<result<List<crose>>>(){}.getType());
               List<crose> data= (List<crose>) r.getData();

                fenleilist fl=new fenleilist(data, fenleiactive.this);
                ListView lv=findViewById(R.id.fllist);
                lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                    @Override
                    public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                        Intent intent=new Intent(fenleiactive.this, course1active.class);
                        startActivity(intent);
                    }
                });

                lv.setAdapter(fl);

            }

            @Override
            public void onFailure(int code, String mes) {

            }
        });

    }
}
